<template>
  <div class="app-header-sticky" :class="{show:top>80}">
    <div class="container" v-show="(top>80)">
      <RouterLink class="logo" to="/" />
      <AppHeaderNav />
      <div class="right">
        <RouterLink to="/">品牌</RouterLink>
        <RouterLink to="/">专题</RouterLink>
      </div>
    </div>
  </div>
</template>
<script>
import AppHeaderNav from '../components/AppHeader-nav.vue'
import { throttle } from '../utils/constfun'
import _ from 'lodash'
export default {
  components: { AppHeaderNav },
  data() {
    return {
      top: 0
    }
  },
  methods: {
    scrollTopTop() {
      this.top = document.documentElement.scrollTop
      // console.log(this.top);
    },
  },
  mounted() {
    // 没有节流实现
    // window.addEventListener('scroll',this.scrollTopTop)
    // 传统节流实现
    // window.addEventListener('scroll', throttle(this.scrollTopTop))
    // 插件节流实现
    window.addEventListener('scroll', _.throttle(this.scrollTopTop, 200))
    // window.addEventListener('scroll', () => {
    //     this.top = document.documentElement.scrollTop
    //     console.log(this.top);
    //   })
  },
  // destroyed() {
  //   window.removeEventListener('scroll',this.scrollTopTop)
  // },
  beforeDestroy() {
    window.removeEventListener('scroll', throttle(this.scrollTopTop))
  }
}
</script>

<style lang="scss" scoped>
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99999;
  background-color: #fff;
  box-shadow: 0 0 10px black;
  border-bottom: 1px solid #e4e4e4;
  transform: translateY(-100%);
  opacity: 0;
  &.show {
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }
  .container {
    display: flex;
    align-items: center;
  }
  .logo {
    width: 200px;
    height: 80px;
    background: url(../assets/download.png) no-repeat right 2px;
    background-size: 160px auto;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid #27ba9b;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: #27ba9b;
      }
    }
  }
}
// .box_fixed{
//     width: 500px;
//     height: 40px;
//     border: 2px dashed pink;
//     border-radius: 20px;
//     margin: 0 auto;
//     line-height: 40px;
//     background: #eee;
//   }
//   .is_fixed{
//     position: fixed;
//     top: 0;
//     left: 50%;
//     margin-left: -250px;
//     z-index: 999;
//   }
</style>